repo: implement list_refs and list_refs_ext
authorFelix Krull <f_krull@gmx.de>
Tue, 9 Oct 2018 19:13:13 +0000 (21:13 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:53 +0000 (12:53 -0400)
rust-bindings/rust/libostree/src/auto/mod.rs
rust-bindings/rust/libostree/src/repo.rs
rust-bindings/rust/sample/src/main.rs

index 2c701c568590358a7060e4fec1a3a5ebea9b1b25..e2509978c1cde402b431cf9f8e0e57d1fb8342c1 100644 (file)
@@ -59,6 +59,7 @@ pub use self::enums::StaticDeltaGenerateOpt;
 mod flags;
 #[cfg(any(feature = "v2015_7", feature = "dox"))]
 pub use self::flags::RepoCommitState;
+pub use self::flags::RepoListRefsExtFlags;
 pub use self::flags::RepoPullFlags;
 pub use self::flags::SePolicyRestoreconFlags;
 
index 1fec31a4e945f27bf650e2aa55978df26e62d916..64e62a94e57189021d319f870c2589304b2a680d 100644 (file)
@@ -1,4 +1,4 @@
-use auto::Repo;
+use auto::{Repo, RepoListRefsExtFlags};
 use ffi;
 use gio;
 use glib;
@@ -6,7 +6,7 @@ use glib::Error;
 use glib::IsA;
 use glib::translate::*;
 use glib_ffi;
-use std::collections::HashSet;
+use std::collections::{HashSet, HashMap};
 use std::ptr;
 use std::path::Path;
 use ObjectName;
@@ -32,7 +32,19 @@ pub trait RepoExtManual {
         &self,
         commit_checksum: &str,
         maxdepth: i32,
-        cancellable: P) -> Result<HashSet<ObjectName>, Error>;
+        cancellable: P
+    ) -> Result<HashSet<ObjectName>, Error>;
+    fn list_refs<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
+        &self,
+        refspec_prefix: P,
+        cancellable: Q
+    ) -> Result<HashMap<String, String>, Error>;
+    fn list_refs_ext<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
+        &self,
+        refspec_prefix: P,
+        flags: RepoListRefsExtFlags,
+        cancellable: Q
+    ) -> Result<HashMap<String, String>, Error>;
 }
 
 impl<O: IsA<Repo> + IsA<glib::Object> + Clone + 'static> RepoExtManual for O {
@@ -57,7 +69,61 @@ impl<O: IsA<Repo> + IsA<glib::Object> + Clone + 'static> RepoExtManual for O {
                 cancellable.into().to_glib_none().0,
                 &mut error,
             );
-            if error.is_null() { Ok(from_glib_container_variant_set(hashtable)) } else { Err(from_glib_full(error)) }
+            if error.is_null() {
+                Ok(from_glib_container_variant_set(hashtable))
+            } else {
+                Err(from_glib_full(error))
+            }
+        }
+    }
+
+    fn list_refs<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
+        &self,
+        refspec_prefix: P,
+        cancellable: Q
+    ) -> Result<HashMap<String, String>, Error> {
+        unsafe {
+            let mut error = ptr::null_mut();
+            let mut hashtable = ptr::null_mut();
+            let _ = ffi::ostree_repo_list_refs(
+                self.to_glib_none().0,
+                refspec_prefix.into().to_glib_none().0,
+                &mut hashtable,
+                cancellable.into().to_glib_none().0,
+                &mut error,
+            );
+
+            if error.is_null() {
+                Ok(FromGlibPtrContainer::from_glib_container(hashtable))
+            } else {
+                Err(from_glib_full(error))
+            }
+        }
+    }
+
+    fn list_refs_ext<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
+        &self,
+        refspec_prefix: P,
+        flags: RepoListRefsExtFlags,
+        cancellable: Q
+    ) -> Result<HashMap<String, String>, Error> {
+        unsafe {
+            let mut error = ptr::null_mut();
+            let mut hashtable = ptr::null_mut();
+            let _ = ffi::ostree_repo_list_refs_ext(
+                self.to_glib_none().0,
+                refspec_prefix.into().to_glib_none().0,
+                &mut hashtable,
+                flags.to_glib(),
+                cancellable.into().to_glib_none().0,
+                &mut error,
+            );
+
+            if error.is_null() {
+                Ok(FromGlibPtrContainer::from_glib_container(hashtable))
+            } else {
+                Err(from_glib_full(error))
+            }
         }
     }
 }
index 8e1ef5b8046de3977a4f559c1d0c6075f28acb69..02405f9c7c10c4e155ed296461c934702dfd3aac 100644 (file)
@@ -10,11 +10,13 @@ use libostree::prelude::*;
 fn main() {
     let repo = libostree::Repo::new_for_path("../../../repo-bare");
 
-    //let result = repo.create(libostree::RepoMode::Archive, Option::None);
-    //result.expect("we did not expect this to fail :O");
-
     repo.open(None).expect("should have opened");
 
+    let refs = repo.list_refs(None, None).unwrap();
+    for (refspec, checksum) in refs {
+        println!("  {} = {}", refspec, checksum);
+    }
+
     let (file, checksum) = repo.read_commit("test", None).unwrap();
 
     println!("path: {:?}", file.get_path());